﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Chinaer.Dao.EF
{
    public class AreaDAO : Repository<Model.Entities.Model_Area>, IDao.IAreaDAO
    {

        public bool EnableTrack
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public IList<Model.Entities.Model_Area> Query(string sql, int pageIndex, out int recordCount, int pageSize, params System.Data.SqlClient.SqlParameter[] sqlParams)
        {
            return base.Query(sql, pageIndex, out recordCount, pageSize, sqlParams);
        }

        public Model.Entities.Model_Area GetByID(string id)
        {
            using (ChinaerContext context = ChinaerContext.GetNewInstance())
            {
                return context.Areas.FirstOrDefault(a => a.IsUse == true && a.IsDelete == false && a.ID.Equals(id, StringComparison.InvariantCultureIgnoreCase));

            }
        }

        public bool Exists(string id)
        {
            return GetByID(id) == null ? false : true;
        }

        public bool Add(Model.Entities.Model_Area entity)
        {
            return base.Add(entity);
        }

        public bool Update(Model.Entities.Model_Area entity)
        {
            return base.Update(entity);
        }

        public bool Delete(Model.Entities.Model_Area entity)
        {
            return base.Delete(entity);
        }

        public bool Delete(string id)
        {
            Model.Entities.Model_Area model_Area = GetByID(id);
            return Delete(model_Area);
        }

        public int DeleteByIDs(IList<string> listID)
        {
            throw new NotImplementedException();
        }

        public Model.Entities.Model_Area GetByName(string areaName)
        {
            using (ChinaerContext context = ChinaerContext.GetNewInstance())
            {
                return context.Areas.FirstOrDefault(a => a.IsUse == true && a.IsDelete == false && a.AreaName.Equals(areaName, StringComparison.InvariantCultureIgnoreCase));
            }
        }

        public Model.Entities.Model_Area GetByCode(string areaCode)
        {
            using (ChinaerContext context = ChinaerContext.GetNewInstance())
            {
                return context.Areas.FirstOrDefault(a => a.IsUse == true && a.IsDelete == false && a.AreaCode.Equals(areaCode, StringComparison.InvariantCultureIgnoreCase));
            }
        }


        public List<Model.Entities.Model_Area> GetByCityID(string cityID)
        {
            using (ChinaerContext context = ChinaerContext.GetNewInstance())
            {
                return context.Areas.Where(a => a.IsUse == true && a.IsDelete == false && a.CityID.Equals(cityID, StringComparison.InvariantCultureIgnoreCase)).ToList();
            }
        }
    }
}
